<?php
function generate_password($pwd, $request)
{
	if (!check_array($request) || $pwd == '') {
		return md5('');
	}

	if (strlen($pwd) != 32) $pwd = md5($pwd);

	$name = isset($request['email']) ? md5($request['email']) : md5('');
	$time = isset($request['time']) ? $request['time'] : 0;

	$password = substr($name, strlen($name)-3).
				substr($pwd, 0, 12).
				substr($name, 12, 3).
				substr($pwd, 12, 12).
				substr($name, 24, 3).
				substr($pwd, 24, strlen($pwd)-3).
				substr($name, 0, 3);

	return md5($password.$time);
}

function verify_password($pwd, $user)
{
	return (isset($user['password']) && $user['password'] == generate_password($pwd, $user));
}